import java.util.Scanner;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-07-25
 * Time:10:00
 */
public class Main {
    public static void main(String[] args) {
        int f0 = 0;
        int f1 = 1;
        int f2 = 0;
        int count = 0;
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        while (true) {
            f2 = f1 + f0;
            if (N <= f2){
                if (f2 - N < N - f1){
                    System.out.println(f2-N);
                }else {
                    System.out.println(N-f1);
                }
                break;
            }
            f0 = f1;
            f1 = f2;
        }
    }
}
